﻿using ReactiveUI;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Media;
using Color = System.Windows.Media.Color;

namespace ScienceAIApp.Views.ToolBarPanel;
/// <summary>
/// Interaction logic for MarkListView.xaml
/// </summary>
public partial class MarkListView
{
    public MarkListView()
    {
        InitializeComponent();
        this.WhenActivated(_activated);
    }

    private void _activated(CompositeDisposable disposable)
    {
        //// 上一页
        //this.OneWayBind(
        //    ViewModel,
        //    vm => vm.IsPreVisible,
        //    v => v.PreBlock.Visibility).DisposeWith(disposable);

        //// 下一页
        //this.OneWayBind(
        //    ViewModel,
        //    vm => vm.IsNextVisible,
        //    v => v.NextBlock.Visibility).DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            vm => vm.SelectedBrush,
            v => v.SegBlock.Foreground
        ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SelectMarkPointCommand,
            v => v.Pin1,
            Observable.Return(1),
            nameof(this.Pin1.MouseDown)
        ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SelectMarkPointCommand,
            v => v.Pin2,
            Observable.Return(2),
            nameof(this.Pin2.MouseDown)
        ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SelectMarkPointCommand,
            v => v.Pin3,
            Observable.Return(3),
            nameof(this.Pin3.MouseDown)
        ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SelectMarkPointCommand,
            v => v.Pin4,
            Observable.Return(4),
            nameof(this.Pin4.MouseDown)
        ).DisposeWith(disposable);

        this.BindCommand(
            ViewModel,
            vm => vm.SelectMarkPointCommand,
            v => v.Pin5,
            Observable.Return(5),
            nameof(this.Pin5.MouseDown)
        ).DisposeWith(disposable);

        // 下拉框绑定
        this.Bind(
            ViewModel,
            vm=>vm.SelectedMarkTypeIndex,
            v => v.SegTypeCombox.SelectedIndex
            ).DisposeWith(disposable);

        // 上一页
        this.BindCommand(
            ViewModel,
            vm=>vm.MarkListSwitchCommand,
            v=>v.PreBlock,
            Observable.Return(true),
            nameof(this.PreBlock.MouseDown)
            ).DisposeWith(disposable);

        // 下一页
        this.BindCommand(
            ViewModel,
            vm => vm.MarkListSwitchCommand,
            v => v.NextBlock,
            Observable.Return(false),
            nameof(this.NextBlock.MouseDown)
        ).DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            vm => vm.Pin1,
            v => v.Pin1.Text).DisposeWith(disposable);

        // 是否展示
        this.OneWayBind(
            ViewModel,
            vm => vm.Pin1,
            v => v.BorderPin1.Visibility,
            pin=> pin > 0 ? Visibility.Visible : Visibility.Hidden).DisposeWith(disposable);

        // 选中该状态 
        this.OneWayBind(
            ViewModel,
            vm => vm.IsSelectedPin1,
            v=>v.BorderPin1.BorderThickness,
            isSelected => isSelected ?  new Thickness(2) : new Thickness(0)
            ).DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            vm => vm.Pin2,
            v => v.Pin2.Text).DisposeWith(disposable);

        // 是否展示
        this.OneWayBind(
            ViewModel,
            vm => vm.Pin2,
            v => v.BorderPin2.Visibility,
            pin => pin > 0 ? Visibility.Visible : Visibility.Hidden).DisposeWith(disposable);

        // 选中该状态 
        this.OneWayBind(
            ViewModel,
            vm => vm.IsSelectedPin2,
            v => v.BorderPin2.BorderThickness,
            isSelected => isSelected ? new Thickness(2) : new Thickness(0)
        ).DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            vm => vm.Pin3,
            v => v.Pin3.Text).DisposeWith(disposable);

        // 是否展示
        this.OneWayBind(
            ViewModel,
            vm => vm.Pin3,
            v => v.BorderPin3.Visibility,
            pin => pin > 0 ? Visibility.Visible : Visibility.Hidden).DisposeWith(disposable);

        // 选中该状态 
        this.OneWayBind(
            ViewModel,
            vm => vm.IsSelectedPin3,
            v => v.BorderPin3.BorderThickness,
            isSelected => isSelected ? new Thickness(2) : new Thickness(0)
        ).DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            vm => vm.Pin4,
            v => v.Pin4.Text).DisposeWith(disposable);

        // 是否展示
        this.OneWayBind(
            ViewModel,
            vm => vm.Pin4,
            v => v.BorderPin4.Visibility,
            pin => pin > 0 ? Visibility.Visible : Visibility.Hidden).DisposeWith(disposable);

        // 选中该状态 
        this.OneWayBind(
            ViewModel,
            vm => vm.IsSelectedPin4,
            v => v.BorderPin4.BorderThickness,
            isSelected => isSelected ? new Thickness(2) : new Thickness(0)
        ).DisposeWith(disposable);


        this.OneWayBind(
            ViewModel,
            vm => vm.Pin5,
            v => v.Pin5.Text).DisposeWith(disposable);

        // 是否展示
        this.OneWayBind(
            ViewModel,
            vm => vm.Pin5,
            v => v.BorderPin5.Visibility,
            pin => pin > 0 ? Visibility.Visible : Visibility.Hidden).DisposeWith(disposable);

        // 选中该状态 
        this.OneWayBind(
            ViewModel,
            vm => vm.IsSelectedPin5,
            v => v.BorderPin5.BorderThickness,
            isSelected => isSelected ? new Thickness(2) : new Thickness(0)
        ).DisposeWith(disposable);

        this.OneWayBind(
            ViewModel,
            vm => vm.MarkSum,
            v => v.SumBlock.Text).DisposeWith(disposable);

        // 删除靶点
        this.BindCommand(
            ViewModel,
            vm => vm.DeleteMarkPointCommand,
            v => v.DeletePinBtn
        ).DisposeWith(disposable);

        // 智能划分
        this.BindCommand(
            ViewModel,
            vm=>vm.AiSegCommand,
            v=>v.SegBtn
            ).DisposeWith(disposable);

    }
}
